<?php


abstract class BaseFansub extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $fansub;


	
	protected $web;


	
	protected $afiliado = 0;


	
	protected $fecha_inserccion;


	
	protected $fecha_afiliacion;


	
	protected $tipo_fansub_id;


	
	protected $siglas;

	
	protected $aTipoFansub;

	
	protected $collReleaseXFansubs;

	
	protected $lastReleaseXFansubCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getFansub()
	{

		return $this->fansub;
	}

	
	public function getWeb()
	{

		return $this->web;
	}

	
	public function getAfiliado()
	{

		return $this->afiliado;
	}

	
	public function getFechaInserccion($format = 'Y-m-d')
	{

		if ($this->fecha_inserccion === null || $this->fecha_inserccion === '') {
			return null;
		} elseif (!is_int($this->fecha_inserccion)) {
						$ts = strtotime($this->fecha_inserccion);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [fecha_inserccion] as date/time value: " . var_export($this->fecha_inserccion, true));
			}
		} else {
			$ts = $this->fecha_inserccion;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getFechaAfiliacion($format = 'Y-m-d')
	{

		if ($this->fecha_afiliacion === null || $this->fecha_afiliacion === '') {
			return null;
		} elseif (!is_int($this->fecha_afiliacion)) {
						$ts = strtotime($this->fecha_afiliacion);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [fecha_afiliacion] as date/time value: " . var_export($this->fecha_afiliacion, true));
			}
		} else {
			$ts = $this->fecha_afiliacion;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getTipoFansubId()
	{

		return $this->tipo_fansub_id;
	}

	
	public function getSiglas()
	{

		return $this->siglas;
	}

	
	public function setId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = FansubPeer::ID;
		}

	} 
	
	public function setFansub($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->fansub !== $v) {
			$this->fansub = $v;
			$this->modifiedColumns[] = FansubPeer::FANSUB;
		}

	} 
	
	public function setWeb($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->web !== $v) {
			$this->web = $v;
			$this->modifiedColumns[] = FansubPeer::WEB;
		}

	} 
	
	public function setAfiliado($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->afiliado !== $v || $v === 0) {
			$this->afiliado = $v;
			$this->modifiedColumns[] = FansubPeer::AFILIADO;
		}

	} 
	
	public function setFechaInserccion($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [fecha_inserccion] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->fecha_inserccion !== $ts) {
			$this->fecha_inserccion = $ts;
			$this->modifiedColumns[] = FansubPeer::FECHA_INSERCCION;
		}

	} 
	
	public function setFechaAfiliacion($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [fecha_afiliacion] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->fecha_afiliacion !== $ts) {
			$this->fecha_afiliacion = $ts;
			$this->modifiedColumns[] = FansubPeer::FECHA_AFILIACION;
		}

	} 
	
	public function setTipoFansubId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->tipo_fansub_id !== $v) {
			$this->tipo_fansub_id = $v;
			$this->modifiedColumns[] = FansubPeer::TIPO_FANSUB_ID;
		}

		if ($this->aTipoFansub !== null && $this->aTipoFansub->getId() !== $v) {
			$this->aTipoFansub = null;
		}

	} 
	
	public function setSiglas($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->siglas !== $v) {
			$this->siglas = $v;
			$this->modifiedColumns[] = FansubPeer::SIGLAS;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id = $rs->getInt($startcol + 0);

			$this->fansub = $rs->getString($startcol + 1);

			$this->web = $rs->getString($startcol + 2);

			$this->afiliado = $rs->getInt($startcol + 3);

			$this->fecha_inserccion = $rs->getDate($startcol + 4, null);

			$this->fecha_afiliacion = $rs->getDate($startcol + 5, null);

			$this->tipo_fansub_id = $rs->getInt($startcol + 6);

			$this->siglas = $rs->getString($startcol + 7);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 8; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Fansub object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(FansubPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			FansubPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(FansubPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


												
			if ($this->aTipoFansub !== null) {
				if ($this->aTipoFansub->isModified()) {
					$affectedRows += $this->aTipoFansub->save($con);
				}
				$this->setTipoFansub($this->aTipoFansub);
			}


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = FansubPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += FansubPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			if ($this->collReleaseXFansubs !== null) {
				foreach($this->collReleaseXFansubs as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


												
			if ($this->aTipoFansub !== null) {
				if (!$this->aTipoFansub->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aTipoFansub->getValidationFailures());
				}
			}


			if (($retval = FansubPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->collReleaseXFansubs !== null) {
					foreach($this->collReleaseXFansubs as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}


			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = FansubPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getFansub();
				break;
			case 2:
				return $this->getWeb();
				break;
			case 3:
				return $this->getAfiliado();
				break;
			case 4:
				return $this->getFechaInserccion();
				break;
			case 5:
				return $this->getFechaAfiliacion();
				break;
			case 6:
				return $this->getTipoFansubId();
				break;
			case 7:
				return $this->getSiglas();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = FansubPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getFansub(),
			$keys[2] => $this->getWeb(),
			$keys[3] => $this->getAfiliado(),
			$keys[4] => $this->getFechaInserccion(),
			$keys[5] => $this->getFechaAfiliacion(),
			$keys[6] => $this->getTipoFansubId(),
			$keys[7] => $this->getSiglas(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = FansubPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setFansub($value);
				break;
			case 2:
				$this->setWeb($value);
				break;
			case 3:
				$this->setAfiliado($value);
				break;
			case 4:
				$this->setFechaInserccion($value);
				break;
			case 5:
				$this->setFechaAfiliacion($value);
				break;
			case 6:
				$this->setTipoFansubId($value);
				break;
			case 7:
				$this->setSiglas($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = FansubPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setFansub($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setWeb($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setAfiliado($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setFechaInserccion($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setFechaAfiliacion($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setTipoFansubId($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setSiglas($arr[$keys[7]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(FansubPeer::DATABASE_NAME);

		if ($this->isColumnModified(FansubPeer::ID)) $criteria->add(FansubPeer::ID, $this->id);
		if ($this->isColumnModified(FansubPeer::FANSUB)) $criteria->add(FansubPeer::FANSUB, $this->fansub);
		if ($this->isColumnModified(FansubPeer::WEB)) $criteria->add(FansubPeer::WEB, $this->web);
		if ($this->isColumnModified(FansubPeer::AFILIADO)) $criteria->add(FansubPeer::AFILIADO, $this->afiliado);
		if ($this->isColumnModified(FansubPeer::FECHA_INSERCCION)) $criteria->add(FansubPeer::FECHA_INSERCCION, $this->fecha_inserccion);
		if ($this->isColumnModified(FansubPeer::FECHA_AFILIACION)) $criteria->add(FansubPeer::FECHA_AFILIACION, $this->fecha_afiliacion);
		if ($this->isColumnModified(FansubPeer::TIPO_FANSUB_ID)) $criteria->add(FansubPeer::TIPO_FANSUB_ID, $this->tipo_fansub_id);
		if ($this->isColumnModified(FansubPeer::SIGLAS)) $criteria->add(FansubPeer::SIGLAS, $this->siglas);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(FansubPeer::DATABASE_NAME);

		$criteria->add(FansubPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setFansub($this->fansub);

		$copyObj->setWeb($this->web);

		$copyObj->setAfiliado($this->afiliado);

		$copyObj->setFechaInserccion($this->fecha_inserccion);

		$copyObj->setFechaAfiliacion($this->fecha_afiliacion);

		$copyObj->setTipoFansubId($this->tipo_fansub_id);

		$copyObj->setSiglas($this->siglas);


		if ($deepCopy) {
									$copyObj->setNew(false);

			foreach($this->getReleaseXFansubs() as $relObj) {
				$copyObj->addReleaseXFansub($relObj->copy($deepCopy));
			}

		} 

		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new FansubPeer();
		}
		return self::$peer;
	}

	
	public function setTipoFansub($v)
	{


		if ($v === null) {
			$this->setTipoFansubId(NULL);
		} else {
			$this->setTipoFansubId($v->getId());
		}


		$this->aTipoFansub = $v;
	}


	
	public function getTipoFansub($con = null)
	{
		if ($this->aTipoFansub === null && ($this->tipo_fansub_id !== null)) {
						$this->aTipoFansub = TipoFansubPeer::retrieveByPK($this->tipo_fansub_id, $con);

			
		}
		return $this->aTipoFansub;
	}

	
	public function initReleaseXFansubs()
	{
		if ($this->collReleaseXFansubs === null) {
			$this->collReleaseXFansubs = array();
		}
	}

	
	public function getReleaseXFansubs($criteria = null, $con = null)
	{
				if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collReleaseXFansubs === null) {
			if ($this->isNew()) {
			   $this->collReleaseXFansubs = array();
			} else {

				$criteria->add(ReleaseXFansubPeer::FANSUB_ID, $this->getId());

				ReleaseXFansubPeer::addSelectColumns($criteria);
				$this->collReleaseXFansubs = ReleaseXFansubPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(ReleaseXFansubPeer::FANSUB_ID, $this->getId());

				ReleaseXFansubPeer::addSelectColumns($criteria);
				if (!isset($this->lastReleaseXFansubCriteria) || !$this->lastReleaseXFansubCriteria->equals($criteria)) {
					$this->collReleaseXFansubs = ReleaseXFansubPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastReleaseXFansubCriteria = $criteria;
		return $this->collReleaseXFansubs;
	}

	
	public function countReleaseXFansubs($criteria = null, $distinct = false, $con = null)
	{
				if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(ReleaseXFansubPeer::FANSUB_ID, $this->getId());

		return ReleaseXFansubPeer::doCount($criteria, $distinct, $con);
	}

	
	public function addReleaseXFansub(ReleaseXFansub $l)
	{
		$this->collReleaseXFansubs[] = $l;
		$l->setFansub($this);
	}


	
	public function getReleaseXFansubsJoinRelease($criteria = null, $con = null)
	{
				if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collReleaseXFansubs === null) {
			if ($this->isNew()) {
				$this->collReleaseXFansubs = array();
			} else {

				$criteria->add(ReleaseXFansubPeer::FANSUB_ID, $this->getId());

				$this->collReleaseXFansubs = ReleaseXFansubPeer::doSelectJoinRelease($criteria, $con);
			}
		} else {
									
			$criteria->add(ReleaseXFansubPeer::FANSUB_ID, $this->getId());

			if (!isset($this->lastReleaseXFansubCriteria) || !$this->lastReleaseXFansubCriteria->equals($criteria)) {
				$this->collReleaseXFansubs = ReleaseXFansubPeer::doSelectJoinRelease($criteria, $con);
			}
		}
		$this->lastReleaseXFansubCriteria = $criteria;

		return $this->collReleaseXFansubs;
	}

} 